﻿using SalesSys.DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalesSys.BLL
{
    /// <summary>
    /// 仓库商品历史记录处理类
    /// </summary>
    public class DepotCommodityRecordBLL : BaseBLL<DepotCommodityRecord, Guid>
    {
        /// <summary>
        /// 根据仓库编号查询最新一条仓库商品
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<DepotCommodityRecord> GetCommodityRecordsList(Guid depotId)
        {
            List<DepotCommodityRecord> list = new List<DepotCommodityRecord>();
            Rep.Entities.Where(p => p.Provider.Id == depotId).OrderByDescending(p => p.UpdateTime).GroupBy(p => p.Commodity.Id).ToList().ForEach(i =>
            {
                foreach (var item in i as IGrouping<Guid, DepotCommodityRecord>)
                {
                    list.Add(item);
                }
            });
            return list;
        }

        public  DepotCommodityRecord[] ReacordByNowDepotInfo(Guid depotId)
        {
            var dcmmdBll = new DepotCommodityBLL();
           var re=  dcmmdBll.GetList(p => p.ProviderId == depotId).ToArray();
         return    re.Select(p => DepotCommodityRecord.ToDepotCommodityRecord(p)).ToArray();
        }
    }
}
